package com.jar.exercise.设计模式.visitor模式.双分派;

/**
 * 方法的重载属于静态绑定，可以使用双分派来解决重载
 *
 * person
 * person
 * person
 */
public class StaticBound {
    public static void main(String[] args) {
        OutputName out = new OutputName() ;
        Person p = new Person() ;
        Person man = new Man() ;
        Person woman = new Woman() ;
        out.print(p) ;
        out.print(man) ;
        out.print(woman) ;
    }
}


class Person{
}

class Man extends Person{

}
class Woman extends Person{

}


class OutputName{
    void print(Person p){
        System.out.println("person");
    }
    void print(Man m){
        System.out.println("man");
    }
    void print(Woman w){
        System.out.println("woman");
    }
}

/*

class OutputName{
    void print(Person p){
        if (p instanceof Man) {
            print((Man)p);
        }
        else if (p instanceof Woman) {
            print((Woman) p);
        }
        else System.out.println("person");
    }
    void print(Man m){
        System.out.println("man");
    }
    void print(Woman w){
        System.out.println("woman");
    }
}

 */
 